'use strict';

const Controller = require('egg').Controller;

class NspController extends Controller {

  async exchange() {
    const { ctx, app } = this;
    const nsp = app.io.of('/admin');
    const message = ctx.args[0] || {};
    const socket = ctx.socket;
    const user = socket.user;
    const query = socket.handshake.query;
    const { room } = query
    // const client = socket.id;
    const { action, data } = message
    // console.log(room,action,data)
    if (action == 'redbag') {
      //操作 礼品id = data的这条数据库
    } else if (action == 'ques') {
      //操作 问卷id = data的这条数据库
    }
    nsp.to(room).emit(action, data)
  }
}

module.exports = NspController;
